#include "../lib/Actions.hpp"



void Colon_Cree_Ville (Joueur * J, Unite * U, Partie * P)
{


        if(U->nom == colon)
        {
            Coord * C;


            C = Retourne_Coord (U);
            unsigned int x = Retourne_X (C);
            unsigned int y = Retourne_Y (C);



            Ville * V = Creer_Ville (J,x,y,P);
            if ( V != NULL)
            {
                Supprimer_Unite(J,U);
                Testament_Unite (U);
            }
        }
}



void Ville_Cree_Colon_Bas (Joueur * J, Ville * V, Partie * P)
{
    Coord * C = Retourne_Coord_Ville (V);
    unsigned int x = Retourne_X (C);
    unsigned int y = Retourne_Y (C);

    if ( y == 0 )
    {
        y++;


        if ( ( P->C->CARTE[y+P->C->taille*x] == mer ) && ( P->C->CARTE[y-1+P->C->taille*(x+1)] != mer )&& (!Collision(x+1, y-1, P)))
        {
            Unite * U = Creer_Unite(J,x+1,y-1);
            Creer_Colon (U);
        }
        else if ( ( P->C->CARTE[y+P->C->taille*x] == mer ) && ( P->C->CARTE[y-1+P->C->taille*(x-1)] != mer ) && (!Collision(x-1, y-1, P)))
        {
            Unite * U = Creer_Unite(J,x-1,y-1);
            Creer_Colon (U);
        }
        else if ( !Collision(x, y, P))
        {
            Unite * U = Creer_Unite(J,x,y);
            Creer_Colon (U);
        }
    }
    else if ( y == 11)
    {

        if (  P->C->CARTE[y-1+P->C->taille*(x)] != mer && (!Collision(x, y-1, P) ))
        {
            Ville_Cree_Colon_Haut( J, V,P);
        }
        else if (   P->C->CARTE[y+P->C->taille*(x+1)] != mer  && (!Collision(x+1, y, P)))
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Colon (U);
        }
        else if (  P->C->CARTE[y+P->C->taille*(x-1)] != mer  && (!Collision(x-1, y, P)))
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Colon (U);
        }
    }
    else if ( x == 0)
    {
        if ( ( P->C->CARTE[y+1+x*P->C->taille] == mer ) && ( P->C->CARTE[y-1+P->C->taille*(x)] != mer ) && (!Collision(x, y-1, P)))
        {
            Ville_Cree_Colon_Haut( J, V,P);
        }
        else if ( ( P->C->CARTE[y+1+P->C->taille*x] == mer ) && ( P->C->CARTE[y+P->C->taille*(x+1)] != mer ) && (!Collision(x+1, y, P)))
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Colon (U);
        }
        else if ( !Collision(x, y+1, P))
        {
            Unite * U = Creer_Unite(J,x,y+1);
            Creer_Colon (U);
        }
    }
    else if ( x == 11 )
    {
        if ( ( P->C->CARTE[y+x*P->C->taille] == mer ) && ( P->C->CARTE[y-1+P->C->taille*(x)] != mer ) && (!Collision(x, y-1, P)) )
        {
            Ville_Cree_Colon_Haut( J, V,P);
        }
        else if ( ( P->C->CARTE[x+P->C->taille*y] == mer ) && ( P->C->CARTE[y+P->C->taille*(x-1)] != mer ) && (!Collision(x-1, y, P)))
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Colon (U);
        }
        else if ( !Collision(x, y+1, P))
        {
            Unite * U = Creer_Unite(J,x,y+1);
            Creer_Colon (U);
        }
    }
    else
    {
        y++;

        if ( ( P->C->CARTE[y+x*P->C->taille] == mer ) && ( P->C->CARTE[y-2+P->C->taille*(x)] != mer ) && (!Collision(x, y+2, P)))
        {
            Ville_Cree_Colon_Haut( J, V,P);
        }
        else if ( ( P->C->CARTE[x+P->C->taille*y] == mer ) && ( P->C->CARTE[y-1+P->C->taille*(x+1)] != mer )&& (!Collision(x+1, y-1, P) ))
        {
            Unite * U = Creer_Unite(J,x+1,y-1);
            Creer_Colon (U);
        }
        else if ( ( P->C->CARTE[x+P->C->taille*y] == mer ) && ( P->C->CARTE[y-1+P->C->taille*(x-1)] != mer ) && (!Collision(x-1, y-1, P)))
        {
            Unite * U = Creer_Unite(J,x-1,y-1);
            Creer_Colon (U);
        }
        else if ( !Collision(x, y, P))
        {
            Unite * U = Creer_Unite(J,x,y);
            Creer_Colon (U);
        }
    }

}

void Ville_Cree_Guerrier_Bas (Joueur * J, Ville * V, Partie * P)
{
    Coord * C = Retourne_Coord_Ville (V);
    unsigned int x = Retourne_X (C);
    unsigned int y = Retourne_Y (C);

    if ( y == 0)
    {
        y++;

        if ( ( P->C->CARTE[y+P->C->taille*x] == mer ) && ( P->C->CARTE[y-1+P->C->taille*(x+1)] != mer ) && (!Collision(x+1, y-1, P)))
        {
            Unite * U = Creer_Unite(J,x+1,y-1);
            Creer_Guerrier (U);
        }
        else if ( ( P->C->CARTE[y+P->C->taille*x] == mer ) && ( P->C->CARTE[y-1+P->C->taille*(x-1)] != mer ) && (!Collision(x-1, y+1, P)))
        {
            Unite * U = Creer_Unite(J,x-1,y-1);
            Creer_Guerrier (U);
        }
        else if ( !Collision(x, y, P))
        {
            Unite * U = Creer_Unite(J,x,y);
            Creer_Guerrier (U);
        }
    }
    else if (y == 11 )
    {

        if (  P->C->CARTE[y-1+P->C->taille*(x)] != mer && (!Collision(x, y-1, P)) )
        {
            Ville_Cree_Guerrier_Haut( J, V,P);
        }
        else if (   P->C->CARTE[y+P->C->taille*(x+1)] != mer && (!Collision(x+1, y, P)) )
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Guerrier (U);
        }
        else if (  P->C->CARTE[y+P->C->taille*(x-1)] != mer && (!Collision(x-1, y, P)))
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Guerrier (U);
        }
    }
    else if ( x == 0 )
    {
        if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[(y-1)+P->C->taille*x] != mer )&& (!Collision(x, y-1, P)) )
        {
            Ville_Cree_Guerrier_Haut( J, V,P);
        }
        else if ( ( P->C->CARTE[y+1+P->C->taille*x] == mer ) && ( P->C->CARTE[(y)+P->C->taille*(x+1)] != mer ) && (!Collision(x+1, y, P)))
        {
            Unite * U = Creer_Unite(J,x+1,y-1);
            Creer_Guerrier (U);
        }
        else if ( !Collision(x, y+1, P))
        {
            Unite * U = Creer_Unite(J,x,y+1);
            Creer_Guerrier (U);
        }
    }
    else if ( x == 11)
    {
        if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[(y-1)+P->C->taille*x] != mer ) )
        {
            Ville_Cree_Guerrier_Haut( J, V,P);
        }
        else if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[y+P->C->taille*(x-1)] != mer ) )
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Guerrier (U);
        }
        else if ( !Collision(x, y, P))
        {
            Unite * U = Creer_Unite(J,x,y+1);
            Creer_Guerrier (U);
        }
    }
    else
    {
        if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[(y-1)+P->C->taille*x] != mer ) && (!Collision(x, y-1, P)))
        {
            Ville_Cree_Guerrier_Haut( J, V,P);
        }
        else if ( ( P->C->CARTE[y+1+P->C->taille*x] == mer ) && ( P->C->CARTE[(y)+P->C->taille*(x+1)] != mer )&& (!Collision(x+1, y, P)) )
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Guerrier (U);
        }
        else if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[y+P->C->taille*(x-1)] != mer )&& (!Collision(x-1, y, P)) )
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Guerrier (U);
        }
        else if ( !Collision(x, y+1, P))
        {
            Unite * U = Creer_Unite(J,x,y+1);
            Creer_Guerrier (U);
        }
    }



}

void Ville_Cree_Colon_Haut (Joueur * J, Ville * V, Partie * P)
{
    Coord * C = Retourne_Coord_Ville (V);
    unsigned int x = Retourne_X (C);
    unsigned int y = Retourne_Y (C);

    if ( y == 0 )
    {
        //y--;

        if ( P->C->CARTE[y+1+P->C->taille*(x)] != mer  )
        {
            Ville_Cree_Colon_Bas( J, V,P);
        }
        if (  ( P->C->CARTE[y+P->C->taille*(x+1)] != mer ))
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Colon (U);
        }
        else if ( ( P->C->CARTE[y+P->C->taille*(x-1)] != mer ) )
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Colon (U);
        }
    }
    else if ( y == 11)
    {
        if ( ( P->C->CARTE[y+P->C->taille*x] == mer ) &&  P->C->CARTE[y+P->C->taille*(x+1)] != mer && (!Collision(x+1, y, P)) )
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Colon (U);
        }
        else if (  ( P->C->CARTE[y+P->C->taille*x] == mer ) &&P->C->CARTE[y+P->C->taille*(x-1)] != mer && (!Collision(x-1, y, P)) )
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Colon (U);
        }
        else if ( !Collision(x, y-1, P))
        {
            Unite * U = Creer_Unite(J,x,y-1);
            Creer_Colon (U);
        }
    }
    else if ( x == 0)
    {
        if ( ( P->C->CARTE[y-1+x*P->C->taille] == mer ) && ( P->C->CARTE[y+1+P->C->taille*(x)] != mer )&& (!Collision(x, y+1, P)) )
        {
            Ville_Cree_Colon_Bas( J, V,P);
        }
        else if ( ( P->C->CARTE[y-1+P->C->taille*x] == mer ) && ( P->C->CARTE[y+P->C->taille*(x+1)] != mer )&& (!Collision(x+1, y, P)) )
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Colon (U);
        }
        else if ( !Collision(x, y-1, P))
        {
            Unite * U = Creer_Unite(J,x,y-1);
            Creer_Colon (U);
        }
    }
    else if ( x == 11 )
    {
        if ( ( P->C->CARTE[y+x*P->C->taille] == mer ) && ( P->C->CARTE[y-1+P->C->taille*(x)] != mer ) )
        {
            Ville_Cree_Colon_Bas( J, V,P);
        }
        else if ( ( P->C->CARTE[x+P->C->taille*y] == mer ) && ( P->C->CARTE[y+P->C->taille*(x-1)] != mer ) )
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Colon (U);
        }
        else if ( !Collision(x, y, P))
        {
            Unite * U = Creer_Unite(J,x,y);
            Creer_Colon (U);
        }
    }
    else
    {
        y--;

        if ( ( P->C->CARTE[y+x*P->C->taille] == mer ) && ( P->C->CARTE[y+2+P->C->taille*(x)] != mer )&& (!Collision(x, y+2, P)) )
        {
            Ville_Cree_Colon_Bas( J, V,P);
        }
        else if ( ( P->C->CARTE[x+P->C->taille*y] == mer ) && ( P->C->CARTE[y+1+P->C->taille*(x+1)] != mer ) && (!Collision(x+1, y+1, P)))
        {
            Unite * U = Creer_Unite(J,x+1,y+1);
            Creer_Colon (U);
        }
        else if ( ( P->C->CARTE[x+P->C->taille*y] == mer ) && ( P->C->CARTE[y+1+P->C->taille*(x-1)] != mer )&& (!Collision(x-1, y+1, P)) )
        {
            Unite * U = Creer_Unite(J,x-1,y+1);
            Creer_Colon (U);
        }
        else if ( !Collision(x, y, P))
        {
            Unite * U = Creer_Unite(J,x,y);
            Creer_Colon (U);
        }
    }

}

void Ville_Cree_Guerrier_Haut (Joueur * J, Ville * V, Partie * P)
{
    Coord * C = Retourne_Coord_Ville (V);
    unsigned int x = Retourne_X (C);
    unsigned int y = Retourne_Y (C);

    if ( y == 11 )
    {
        y--;


        if ( ( P->C->CARTE[y+P->C->taille*x] == mer ) && ( P->C->CARTE[x+1+P->C->taille*(y+1)] != mer ) && (!Collision(x+1, y+1, P)))
        {
            Unite * U = Creer_Unite(J,x+1,y+1);
            Creer_Guerrier (U);
        }
        else if ( ( P->C->CARTE[y+P->C->taille*x]  == mer ) && ( P->C->CARTE[x-1+P->C->taille*(y+1)] != mer )&& (!Collision(x-1, y+1, P)))
        {
            Unite * U = Creer_Unite(J,x-1,y+1);
            Creer_Guerrier (U);
        }
        else if ( !Collision(x, y, P))
        {
            Unite * U = Creer_Unite(J,x,y);
            Creer_Guerrier (U);
        }
    }
    else if ( y == 0 )
    {

        if (  P->C->CARTE[y-1+P->C->taille*(x)] != mer && (!Collision(x, y-1, P)) )
        {
            Ville_Cree_Guerrier_Bas( J, V,P);
        }
        else if (   P->C->CARTE[y+P->C->taille*(x+1)] != mer && (!Collision(x+1, y, P)) )
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Guerrier (U);
        }
        else if (  P->C->CARTE[y+P->C->taille*(x-1)] != mer && (!Collision(x-1, y, P)) )
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Guerrier (U);
        }
    }
    else if ( x == 0 )
    {
        if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[(y-1)+P->C->taille*x] != mer )&& (!Collision(x, y-1, P)) )
        {
            Ville_Cree_Guerrier_Bas( J, V,P);
        }
        else if ( ( P->C->CARTE[y+1+P->C->taille*x] == mer ) && ( P->C->CARTE[(y)+P->C->taille*(x+1)] != mer )&& (!Collision(x+1, y, P)) )
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Guerrier (U);
        }
        else if ( !Collision(x, y-1, P))
        {
            Unite * U = Creer_Unite(J,x,y-1);
            Creer_Guerrier (U);
        }
    }
    else if ( x == 11)
    {
        if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[(y-1)+P->C->taille*x] != mer )&& (!Collision(x, y-1, P)) )
        {
            Ville_Cree_Guerrier_Bas( J, V,P);
        }
        else if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[y+P->C->taille*(x-1)] != mer ) && (!Collision(x-1, y, P)))
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Guerrier (U);
        }
        else if ( !Collision(x, y-1, P))
        {
            Unite * U = Creer_Unite(J,x,y-1);
            Creer_Guerrier (U);
        }
    }
    else
    {
        if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[(y-1)+P->C->taille*x] != mer )&& (!Collision(x, y+1, P)) )
        {
            Ville_Cree_Guerrier_Bas( J, V,P);
        }
        else if ( ( P->C->CARTE[y+1+P->C->taille*x] == mer ) && ( P->C->CARTE[(y)+P->C->taille*(x+1)] != mer ) && (!Collision(x+1, y, P)))
        {
            Unite * U = Creer_Unite(J,x+1,y);
            Creer_Guerrier (U);
        }
        else if ( ( P->C->CARTE[y+1+P->C->taille*x]  == mer ) && ( P->C->CARTE[y+P->C->taille*(x-1)] != mer ) && (!Collision(x-1, y, P)))
        {
            Unite * U = Creer_Unite(J,x-1,y);
            Creer_Guerrier (U);
        }
        else if ( !Collision(x, y, P))
        {
            Unite * U = Creer_Unite(J,x,y-1);
            Creer_Guerrier (U);
        }
    }

}

void Attaquer_Haut(Joueur * J, Unite * A, Partie * P)
{
    Unite * D;
    Ville * V;
    Coord * C1;
    unsigned int xd, yd;
    int mort = 0;

    Coord * C = Retourne_Coord(A);
    unsigned int xa = Retourne_X (C);
    unsigned int ya = Retourne_Y (C) - 1;


    for(unsigned int i = 0; i < P->IA->nb_unite; i++)
    {
        D = Retourne_Unite (P->IA,i);
        C1 = Retourne_Coord(D);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer(A,D);

            if(mort == 1)
            {
                Supprimer_Unite(J,A);
            }
            if(mort == 2)
            {
                Supprimer_Unite(P->IA,D);
            }
        }
    }

    for(unsigned int i = 0; i < P->IA->nb_ville; i++)
    {
        V = Retourne_Ville (P->IA,i);
        C1 = Retourne_Coord_Ville(V);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer_Ville(A,V);

            if(mort == 1)
            {
                Supprimer_Ville (P->IA,V);
            }
        }
    }
}


void Attaquer_Bas(Joueur * J, Unite * A, Partie * P)
{
    Unite * D;
    Ville * V;
    Coord * C1;
    unsigned int xd, yd;
    int mort = 0;

    Coord * C = Retourne_Coord(A);
    unsigned int xa = Retourne_X (C);
    unsigned int ya = Retourne_Y (C) + 1;


    for(unsigned int i = 0; i < P->IA->nb_unite; i++)
    {
        D = Retourne_Unite (P->IA,i);
        C1 = Retourne_Coord(D);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer(A,D);

            if(mort == 1)
            {
                Supprimer_Unite(J,A);
            }
            if(mort == 2)
            {
                Supprimer_Unite(P->IA,D);
            }
        }
    }

    for(unsigned int i = 0; i < P->IA->nb_ville; i++)
    {
        V = Retourne_Ville (P->IA,i);
        C1 = Retourne_Coord_Ville(V);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer_Ville(A,V);

            if(mort == 1)
            {
                Supprimer_Ville (P->IA,V);
            }
        }
    }
}

void Attaquer_Gauche(Joueur * J, Unite * A, Partie * P)
{
    Unite * D;
    Ville * V;
    Coord * C1;
    unsigned int xd, yd;
    int mort = 0;

    Coord * C = Retourne_Coord(A);
    unsigned int xa = Retourne_X (C) - 1;
    unsigned int ya = Retourne_Y (C);


    for(unsigned int i = 0; i < P->IA->nb_unite; i++)
    {
        D = Retourne_Unite (P->IA,i);
        C1 = Retourne_Coord(D);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer(A,D);

            if(mort == 1)
            {
                Supprimer_Unite(J,A);
            }
            if(mort == 2)
            {
                Supprimer_Unite(P->IA,D);
            }
        }
    }

    for(unsigned int i = 0; i < P->IA->nb_ville; i++)
    {
        V = Retourne_Ville (P->IA,i);
        C1 = Retourne_Coord_Ville(V);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer_Ville(A,V);

            if(mort == 1)
            {
                Supprimer_Ville (P->IA,V);
            }
        }
    }
}

void Attaquer_Droite(Joueur * J, Unite * A, Partie * P)
{
    Unite * D;
    Ville * V;
    Coord * C1;
    unsigned int xd, yd;
    int mort = 0;

    Coord * C = Retourne_Coord(A);
    unsigned int xa = Retourne_X (C) + 1;
    unsigned int ya = Retourne_Y (C);


    for(unsigned int i = 0; i < P->IA->nb_unite; i++)
    {
        D = Retourne_Unite (P->IA,i);
        C1 = Retourne_Coord(D);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer(A,D);

            if(mort == 1)
            {
                Supprimer_Unite(J,A);
            }
            if(mort == 2)
            {
                Supprimer_Unite(P->IA,D);
            }
        }
    }

    for(unsigned int i = 0; i < P->IA->nb_ville; i++)
    {
        V = Retourne_Ville (P->IA,i);
        C1 = Retourne_Coord_Ville(V);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer_Ville(A,V);

            if(mort == 1)
            {
                Supprimer_Ville (P->IA,V);
            }
        }
    }
}

void Attaquer_Haut_IA(Joueur * J, Unite * A, Partie * P)
{
    Unite * D;
    Ville * V;
    Coord * C1;
    unsigned int xd, yd;
    int mort = 0;

    Coord * C = Retourne_Coord(A);
    unsigned int xa = Retourne_X (C);
    unsigned int ya = Retourne_Y (C) - 1;


    for(unsigned int i = 0; i < P->Jhumain->nb_unite; i++)
    {
        D = Retourne_Unite (P->Jhumain,i);
        C1 = Retourne_Coord(D);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer(A,D);

            if(mort == 1)
            {
                Supprimer_Unite(J,A);
            }
            if(mort == 2)
            {
                Supprimer_Unite(P->Jhumain,D);
            }
        }
    }

    for(unsigned int i = 0; i < P->Jhumain->nb_ville; i++)
    {
        V = Retourne_Ville (P->Jhumain,i);
        C1 = Retourne_Coord_Ville(V);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer_Ville(A,V);

            if(mort == 1)
            {
                Supprimer_Ville (P->Jhumain,V);
            }
        }
    }
}


void Attaquer_Bas_IA(Joueur * J, Unite * A, Partie * P)
{
    Unite * D;
    Ville * V;
    Coord * C1;
    unsigned int xd, yd;
    int mort = 0;

    Coord * C = Retourne_Coord(A);
    unsigned int xa = Retourne_X (C);
    unsigned int ya = Retourne_Y (C) + 1;


    for(unsigned int i = 0; i < P->Jhumain->nb_unite; i++)
    {
        D = Retourne_Unite (P->Jhumain,i);
        C1 = Retourne_Coord(D);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer(A,D);

            if(mort == 1)
            {
                Supprimer_Unite(J,A);
            }
            if(mort == 2)
            {
                Supprimer_Unite(P->Jhumain,D);
            }
        }
    }

    for(unsigned int i = 0; i < P->Jhumain->nb_ville; i++)
    {
        V = Retourne_Ville (P->Jhumain,i);
        C1 = Retourne_Coord_Ville(V);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer_Ville(A,V);

            if(mort == 1)
            {
                Supprimer_Ville (P->Jhumain,V);
            }
        }
    }
}

void Attaquer_Gauche_IA(Joueur * J, Unite * A, Partie * P)
{
    Unite * D;
    Ville * V;
    Coord * C1;
    unsigned int xd, yd;
    int mort = 0;

    Coord * C = Retourne_Coord(A);
    unsigned int xa = Retourne_X (C) - 1;
    unsigned int ya = Retourne_Y (C);


    for(unsigned int i = 0; i < P->Jhumain->nb_unite; i++)
    {
        D = Retourne_Unite (P->Jhumain,i);
        C1 = Retourne_Coord(D);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer(A,D);

            if(mort == 1)
            {
                Supprimer_Unite(J,A);
            }
            if(mort == 2)
            {
                Supprimer_Unite(P->Jhumain,D);
            }
        }
    }

    for(unsigned int i = 0; i < P->Jhumain->nb_ville; i++)
    {
        V = Retourne_Ville (P->Jhumain,i);
        C1 = Retourne_Coord_Ville(V);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer_Ville(A,V);

            if(mort == 1)
            {
                Supprimer_Ville (P->Jhumain,V);
            }
        }
    }
}

void Attaquer_Droite_IA(Joueur * J, Unite * A, Partie * P)
{
    Unite * D;
    Ville * V;
    Coord * C1;
    unsigned int xd, yd;
    int mort = 0;

    Coord * C = Retourne_Coord(A);
    unsigned int xa = Retourne_X (C) + 1;
    unsigned int ya = Retourne_Y (C);


    for(unsigned int i = 0; i < P->Jhumain->nb_unite; i++)
    {
        D = Retourne_Unite (P->Jhumain,i);
        C1 = Retourne_Coord(D);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer(A,D);

            if(mort == 1)
            {
                Supprimer_Unite(J,A);
            }
            if(mort == 2)
            {
                Supprimer_Unite(P->Jhumain,D);
            }
        }
    }

    for(unsigned int i = 0; i < P->Jhumain->nb_ville; i++)
    {
        V = Retourne_Ville (P->Jhumain,i);
        C1 = Retourne_Coord_Ville(V);
        xd = Retourne_X (C1);
        yd = Retourne_Y (C1);

        if(xd == xa && yd == ya)
        {
            mort = Attaquer_Ville(A,V);

            if(mort == 1)
            {
                Supprimer_Ville (P->Jhumain,V);
            }
        }
    }
}
